﻿using DataAccessObject;
using DataAccessObject.DAO;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace QLHocVu.GUI
{
    public partial class Home : Form
    {
        #region
        private KhoiLopDAO khoilopDAO = new KhoiLopDAO();
        private NamHocDAO namhocDAO = new NamHocDAO();
        private LopHocDAO lophocDAO = new LopHocDAO();
        private MonHocDAO monhocDAO = new MonHocDAO();
        #endregion

        public Home()
        {
            InitializeComponent();
            ////////////////////////
            InitializeContent();
        }

        #region event
        private void tabControl2_Click(object sender, EventArgs e)
        {

        }

        private void tabControl1_Click(object sender, EventArgs e)
        {

        }

        private void tabControlPanel1_Click(object sender, EventArgs e)
        {

        }

        private void mônHọcToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ThemMonHoc themMonHocForm = new ThemMonHoc();
            themMonHocForm.Show();
        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void buttonX9_Click(object sender, EventArgs e)
        {
            DiemCacNamTruocForm diemCacNamTruocForm = new DiemCacNamTruocForm();
            diemCacNamTruocForm.Show();
        }

        private void thêmMônHọcToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ThemMonHoc themMonHocForm = new ThemMonHoc();
            themMonHocForm.Show();
        }

        private void buttonX3_Click(object sender, EventArgs e)
        {
            DangNhap dangNhapForm = new DangNhap();
            dangNhapForm.Show();
        }

        private void danhSáchGiáoViênToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DanhSachGiaoVien danhSachGiaoVien = new DanhSachGiaoVien();
            danhSachGiaoVien.Show();
        }

        private void chiTiếtPhânCôngToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ChiTietPhanCong chiTietPhanCongForm = new ChiTietPhanCong();
            chiTietPhanCongForm.Show();
        }

        private void labelX7_Click(object sender, EventArgs e)
        {

        }

        private void comboBoxEx7_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void labelX23_Click(object sender, EventArgs e)
        {

        }

        private void comboBoxEx8_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void phânCôngToolStripMenuItem_Click(object sender, EventArgs e)
        {
            PhanCong phanCongForm = new PhanCong();
            phanCongForm.Show();
        }

        private void lớpHọcToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LopHoc lopHocForm = new LopHoc();
            //lopHocForm.Location = new Point(600, 600);
            lopHocForm.Show();

        }

        private void btnImportHocSinh_Click(object sender, EventArgs e)
        {
            openFileDialogNhapHocSinh.ShowDialog();
        }

        private void btnXemLopChuNhiem_Click(object sender, EventArgs e)
        {
            tabLopChuNhiem.Visible = true;
            tabLopChuNhiem.Text = "Lớp Chủ Nhiệm";
            tabControl.SelectNextTab();
        }

        private void btnXemLopDangHoc_Click(object sender, EventArgs e)
        {
            tabLopChuNhiem.Visible = true;
            tabLopChuNhiem.Text = "Lớp Đang Học";
            tabControl.SelectPreviousTab();
        }
        #endregion

        private void InitializeContent()
        {
            ReloadAllCbb();
        }

        private void ReloadAllCbb()
        {
            ReloadCbbKhoiLop();
            ReloadCbbNamHoc();
            ReloadCbbLopHocHocSinh();
        }

        private void ReloadCbbKhoiLop()
        {
            var source = khoilopDAO.getAll();
            cbbKhoiLop.DataSource = source;
            cbbKhoiLop.SelectedIndex = source.Count - 1;
        }

        private void ReloadCbbNamHoc()
        {
            var source = namhocDAO.getAll();
            cbbNamHoc.DataSource = source;
        }

        private void ReloadCbbLopHocHocSinh()
        {
            var khoilop = cbbKhoiLop.SelectedItem as KHOILOP;
            var namhoc = cbbNamHoc.SelectedItem as NAMHOC;

            if (namhoc != null && khoilop != null)
                cbbLopHocHocSinh.DataSource = lophocDAO.getByNamHocAndKhoiLop(namhoc, khoilop);
        }

        private void ReloadCbbLopHocGiaoVien()
        {
            var magiaovien = tbMaGiaoVien.Text;
            var lophocs = lophocDAO.getByMaGiaoVien(magiaovien);

            cbbLopHocGiaoVien.DataSource = lophocs;
        }

        private void ReloadCbbMonHocGiaoVien()
        {
            var magiaovien = tbMaGiaoVien.Text;
            //var monhocs = monhocDAO.getByMaGiaoVien(magiaovien);

            //cbbMonHocGiaoVien.DataSource = monhocs;
        }
    }
}
